package com.nondo.dean.platform.tool;

import com.nondo.dean.common.tool.AliyunOssTool;
import com.nondo.dean.common.tool.PropertiesTools;
import com.nondo.dean.platform.domain.Attach;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author ken.
 * @version 1.0
 * @email 695093513@qq.com
 * @date 2018/3/30
 */
public class FilePathUtils {
    @Autowired
    AliyunOssTool aliyunOssTool;

    public static String ossAttachServerDomain = PropertiesTools.getPropertyValue("aliyun_oss.endpoint");

    /**
     * 获取文件图片url地址
     *
     * @param attach
     * @return
     */
    public static Attach getFileUrl(Attach attach) {
        if (attach != null && attach.getPath() != null) {
            String newPath = getFileUrl(attach.getPath());
            attach.setPath(newPath);
        }
        return attach;
    }

    /**
     * 获取文件图片url地址
     *
     * @param path
     * @return
     */
    public static String getFileUrl(String path) {

        int isFull = path.indexOf("http");
        if (isFull >= 0) {
            return path;
        }

        return ossAttachServerDomain + "/" + path;
    }
}
